﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Data;

public partial class CustomerReports : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridView1.DataSource = CusSqlDataSource;
            GridView1.DataBind();

        }
    }
    protected void selectall_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow dr in GridView1.Rows)
        {

            CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
            chk.Checked = true;

        }

    }
    protected void deselectall_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow dr in GridView1.Rows)
        {

            CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
            chk.Checked = false;

        }
    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                Thread.CurrentThread.CurrentCulture.DateTimeFormat = new CultureInfo("en-US", false).DateTimeFormat;



            }
        }
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Attributes.Add("onmouseover", "this.Mystyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFA8'");

        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.Mystyle");
        //}
    }
    protected void genreport_Click(object sender, EventArgs e)
    {
            string myval = "";
            foreach (GridViewRow dr in GridView1.Rows)
            {
                CheckBox chk = (CheckBox)dr.FindControl("chkAdd");
                if (chk.Checked)
                {
                    myval += chk.ToolTip + ",";
                }

            }
            myval = myval.Trim(",".ToCharArray()[0]);

           if(RadioButtonList1.SelectedValue=="1")

               Response.Redirect("~/reps2.aspx?rep=" + "CustomerReport" + "&id=" + myval + "&sid=" + myval);
               else

               Response.Redirect("~/reps2.aspx?rep=" + "CustomerReport" + "&id=" + myval + "&sid=0" );


    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {

        search();
    }
    public void search()
    {

        if (searchfield.Text.Length != 0)
        {


            Label1.Text = "";

            DataSet ds;

            string loadsearch = DB.remove_spaces(searchfield.Text);

            if (DropDownList1.SelectedValue == "0")
            {
                ds = DB.quick_search("companies", loadsearch);
            }
            else
            {
                ds = DB.quick_search("companies", loadsearch, DropDownList1.SelectedValue);
            }

           
            if (ds.Tables[0].Rows.Count > 0)
            {


                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                Label1.Visible = false;

            }
            else
            {

                Label1.Visible = true;

            }


        }
        else
        {

            Label1.Text = " من فضلك لا يجوز ترك هذا الحقل خاليا";
            Label1.Visible = true;
        }


    }
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        search();
    }
}
